<template>
	<view>
		<view class="missionTeam">
			<!-- <view class="topbar">
				<button class="cu-btn round bg-blue"
					@click="this.$openrul(`/pages/addTeam/addTeam?id=${taskId}`)">创建队伍</button>
			</view> -->

			<view class="cu-card dynamic" :class="isCard ? 'no-card' : ''" v-for="item in teamList" :key="item.id"
				@click="$openrul(`/subpackage/competitionTeamDetail/competitionTeamDetail?id=${item.id}`)">
				<view class="cu-item  shadow">
					<view class="cu-list comment ">
						<view class="cu-item padding-sm">
							<view class="content">
								<view class="lddq">
									<view class="text-blue text-content text-xl">{{ item.name }}</view>
									<view class="" style="width: 50%;display: flex;justify-content: flex-end;">
										<!-- <view class="">
											
										</view> -->
										<view class="" style="color: #999;font-size: 12px;">
											竞赛任务：{{ item.innovation.name }}
										</view>
									</view>
								</view>
								<view class="text-gray text-content text-df">
									<text class="cuIcon-notificationfill text-blue" style="margin-right: 10rpx;"></text>
									{{ item.detail }}
								</view>
								<view class="bg-white radius margin-top-sm  text-sm">
									<view class="flex">
										<text class="cuIcon-friendfill text-blue" style="margin-right: 10rpx;"></text>
										<view class="flex-sub">{{ item.team_useridsCount }}/{{ item.max_num }}</view>
									</view>
								</view>
								<view class="margin-top-sm flex justify-between">
									<view class="text-gray text-df">
										<text class="cuIcon-timefill text-blue" style="margin-right: 10rpx;"></text>
										{{ item.createtime }}
									</view>
									<!-- <view> -->
									<button class="cu-btn round bg-green" v-if="item.is_join == 0 && item.status == 0"
										@tap.stop="joinTaskTeam(item.id)">加入团队</button>
									<button class="cu-btn round bg-green" v-if="item.is_join == 1">已加入</button>
									<button class="cu-btn round bg-yellow" v-if="item.status == 1">已评选</button>
									<button class="cu-btn round bg-yellow" v-if="item.status == 2">已截止</button>
								</view>
							</view>
							<view class="captain"
								@tap.stop="$openrul(`/pages/userInfo/userInfo?userid=${item.captain.id}`)">
								<view class="cu-avatar round"
									:style="{ 'background-image': `url(${item.captain.avatar})` }"></view>
								<view class="text-gray text-content text-df	"
									style="line-height: 50px;margin-left: 10px;">{{
										item.captain.nickname }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>


	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskId: '',
				teamList: [],
				TeamList: {
					is_own: '',
					innovation_id: '',
					page: 1,
					status: '',
					limit: 1000,
				}
			}
		},
		onLoad(query) {
			// let token = JSON.parse(uni.getStorageSync('vuexvuex'))
			// var parsedData = JSON.parse(token.value);
			// var tokenValue = parsedData.userinfo.token; 

			this.taskId = query.id || '';

			this.getTeamTaskList()

		},
		methods: {
			async joinTaskTeam(team_id) {
				uni.showModal({
					title: '提示',
					content: '是否申请加入该队伍？',
					success: res => {
						if (res.confirm) {
							this.$myHttp.post({
								url: this.$myHttp.urlMap.joinTaskTeam,
								data: {
									team_id: team_id
								}
							}).then(res => {
								if (res.code == 1) {
									uni.showToast({
										title: '已申请，待队长审核！',
										icon: 'none'
									})
								}
							})



						}
					}
				});
				// let res = await this.$myHttp.post({
				// 	url: this.$myHttp.urlMap.joinTaskTeam,
				// 	data: {
				// 		team_id: team_id
				// 	}
				// })

				// if (res.code == 1) {
				// 	uni.showToast({
				// 		title: '已申请加入队伍',
				// 		icon: 'none'
				// 	})
				// }
			},

			async getTeamTaskList() {
				let res = await this.$myHttp.post({

					url: this.$myHttp.urlMap.getTeamList,
					data: this.TeamList,
					need_login: true,

				})
				this.teamList = res.data.data
				console.log('this.teamList: ', this.teamList)
				// 反转数组
				this.teamList = this.teamList.reverse()

			},
			gotoTeamDetail() {
				uni.navigateTo({
					url: '/pages/teamDetail/teamDetail'
				})
			}
		}
	}
</script>

<style>
	page {
		background: #F8F8F8;
	}

	.captain {
		display: flex;
		align-items: center;
	}

	.missionTeam .topbar {
		width: 100%;
		height: 130px;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #fff;
	}
</style>